package com.only4play.practice.common.utils;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 数字格式化工具类
 * @author mengdy
 */

public class NumberFormatUtils {

    /**
     * 分转化为元保留两位小数
     */
    public static BigDecimal fen2yuan(int amount){
        BigDecimal num = new BigDecimal(amount);
        return num.divide(new BigDecimal(100),2, RoundingMode.FLOOR);
    }

    public static BigDecimal fen2yuan(Long amount){
        BigDecimal num = new BigDecimal(amount);
        return num.divide(new BigDecimal(100),2, RoundingMode.FLOOR);
    }

    public static BigDecimal fen2yuan(BigDecimal amount){
        if (amount == null) {
            amount = BigDecimal.ZERO;
        }
        return amount.divide(new BigDecimal(100),2, RoundingMode.FLOOR);
    }
}
